# !/usr/bin/env python
# -*- coding: utf-8 -*-
"""
 -------------------------------------------------
    File Name:     log_manager.py
    Description:   日志模块: 初始化日志记录，支持控制台和文件多级日志输出
 -------------------------------------------------
 """
import logging
import os
from apitesting.config import paths

logs_dir = paths.LOGS_DIR


def initialize_logging():
    """初始化日志记录"""
    if not os.path.exists(logs_dir):
        os.makedirs(logs_dir)

    log_file = os.path.join(logs_dir, "run.log")
    logging.basicConfig(
        level=logging.INFO,
        format="%(asctime)s [%(levelname)s] %(message)s",
        handlers=[
            logging.FileHandler(log_file, encoding="utf-8"),
            logging.StreamHandler()
        ]
    )
    logging.info("日志初始化完成")
